package com.blackline.auto.Report;

import static org.junit.Assert.fail;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

import com.blackline.declareUI.UI;
import com.blackline.parameters.Parameters;
import com.blackline.parameters.TestData;

/**
 * 			Testing environment: T2
 * 			Instance: Test 2
 *          This is to run a single standard report with name User Role Assignemnts
 */


public class RunStdReport {
	private WebDriver driver;
	Parameters parameters;

	private StringBuffer verificationErrors = new StringBuffer();
	private static Logger logger = Logger.getLogger(RunStdReport.class);
	UI UI = new UI();

	int sleepTime = 2000;

	
	@Before
	public void setUp() throws Exception
	{
		FirefoxProfile profile = new FirefoxProfile();
		parameters=new Parameters("parameters.xml");

		profile.setEnableNativeEvents(true);

		driver = new FirefoxDriver();
		driver.manage().window().maximize();
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		 
		UI.declareAllUI(driver);
	}
	
	@After
	public void tearDown() throws Exception
	{
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString))
		{
			fail(verificationErrorString);
		}
	}
	
	@Test
	public void RunReport() throws Exception
	{
		
		logger.info("You've selected site: https://t2.blacklineondemand.com/Test3");
		UI.LogonPage.Login(driver, "https://t2.blacklineondemand.com/Test2", parameters.getLogonID("admin"), parameters.getPassword("admin"));
		Thread.sleep(sleepTime);
		
		Run_One_Report();
	}
	
	 
	public void Run_One_Report() throws Exception
	{
		
		Thread.sleep(sleepTime);
		
		UI.NavigationMenu.REPORTS.click();
		UI.Reports.Enhanced_Reporting_link.click();
		Thread.sleep(sleepTime); 
		
		logger.info("=====Accounts Node=====");
		
		//Click on Account Node
		UI.Reporting.AddIcon_BlackLineReports.click();
		Thread.sleep(sleepTime);
		UI.Reporting.AddIcon_Account.click();
		Thread.sleep(sleepTime);
		UI.Reporting.Accounts_nodeInLeftTree.click();
		Thread.sleep(sleepTime);
		
		UI.Reporting.Name_text_field.clear();
		UI.Reporting.Description_text_field.clear();
		UI.Reporting.Name_text_field.clear();
		
		UI.Reporting.Name_text_field.sendKeys("User Role Assignments"); 
		UI.Reporting.Name_text_field.sendKeys(Keys.RETURN);
		Thread.sleep(sleepTime);

		UI.Reporting.Run_linkOfSearchedResult.click();
		Thread.sleep(sleepTime);
		UI.Reporting.Run_Report_button.click();
		Thread.sleep(sleepTime+3000);
		UI.Reporting.OK_button.click();
		Thread.sleep(sleepTime);

	}
	
}







